package com.cug.nageoffer.common.controller;


import com.cug.nageoffer.common.service.EnterpriseService;
import com.cug.nageoffer.model.vo.EnterpriseDetailVo;
import com.cug.nageoffer.model.vo.EnterpriseVo;
import com.cug.nageoffer.model.vo.Result;
import com.cug.nageoffer.model.vo.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "公司相关")
@RestController
@RequestMapping(value = "/api/index/enterprise")
@Slf4j
public class EnterpriseController {

    @Autowired
    private EnterpriseService enterpriseService;

    @Operation(summary = "根据公司id查询公司")
    @GetMapping(value = "/getById/{id}")
    public Result<EnterpriseDetailVo> getById(@PathVariable Long id) {
        EnterpriseDetailVo enterprise = enterpriseService.getById(id);
        return Result.build(enterprise, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据行业类型分页查询公司")
    @GetMapping(value = "/page/getEnterpriseInfoByType/{pageNum}/{pageSize}")
    public Result<PageInfo<EnterpriseVo>> getEnterpriseInfoByType(@RequestParam String type
            , @PathVariable Integer pageNum, @PathVariable Integer pageSize) {
//        log.info("根据公司行业类型查询公司，类型：{}，第{}页，共{}条", type, pageNum, pageSize);
        PageInfo<EnterpriseVo> pageInfo = enterpriseService.getEnterpriseInfoByType(type, pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询热门企业")
    @GetMapping(value = "/getHotEnterprise")
    public Result<List<EnterpriseVo>> getHotEnterprise() {
        List<EnterpriseVo> list = enterpriseService.getHotEnterprise();
        return Result.build(list, ResultCodeEnum.SUCCESS);

    }


}
